<?php
class MailVo extends SzAbstractMySqlVo
{

    private $mailId;
    private $userId;
    private $icon;
    private $name;
    private $content;
    private $annexList;
    private $isDel;
    private $isRead;
    private $createTime;

    /**
     * Initialize MailVo.
     *
     * @param $mailId
     * @param $userId
     * @param $icon
     * @param $name
     * @param $content
     * @param $annexList
     * @param $isDel
     * @param $isRead
     * @param $createTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return MailVo
     */
    public function __construct($mailId, $userId, $icon, $name, $content, $annexList, $isDel, $isRead, $createTime, $isInsert = false) {
        $this->mailId = $mailId;
        $this->userId = $userId;
        $this->icon = $icon;
        $this->name = $name;
        $this->content = $content;
        $this->annexList = json_decode($annexList, true);
        $this->isDel = $isDel;
        $this->isRead = $isRead;
        $this->createTime = $createTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'MailVo';
        $this->ormName = 'Mail';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'mailId' => $this->getMailId(),
            'userId' => $this->getUserId(),
            'icon' => $this->getIcon(),
            'name' => $this->getName(),
            'content' => $this->getContent(),
            'annexList' => ($needEncode) ? $this->getAnnexList() : $this->getRawAnnexList(),
            'isDel' => $this->getIsDel(),
            'isRead' => $this->getIsRead(),
            'createTime' => $this->getCreateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'mailId' => $this->getMailId(),
            'userId' => $this->getUserId(),
            'icon' => $this->getIcon(),
            'name' => $this->getName(),
            'content' => $this->getContent(),
            'annexList' => ($needEncode) ? $this->getAnnexList() : $this->getRawAnnexList(),
            'isDel' => $this->getIsDel(),
            'isRead' => $this->getIsRead(),
            'createTime' => $this->getCreateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getMailId(),
            $this->getUserId(),
            $this->getIcon(),
            $this->getName(),
            $this->getContent(),
            $this->getAnnexList(),
            $this->getIsDel(),
            $this->getIsRead(),
            $this->getCreateTime(),
        );
    }

    public function getMailId()
    {
        return $this->mailId;
    }

    public function setMailId($val)
    {
        $this->saveColumnStatus(0, $this->mailId);
        $this->mailId = $val;
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(1, $this->userId);
        $this->userId = $val;
    }

    public function getIcon()
    {
        return $this->icon;
    }

    public function setIcon($val)
    {
        $this->saveColumnStatus(2, $this->icon);
        $this->icon = $val;
    }

    public function getName()
    {
        return $this->name;
    }

    public function setName($val)
    {
        $this->saveColumnStatus(3, $this->name);
        $this->name = $val;
    }

    public function getContent()
    {
        return $this->content;
    }

    public function setContent($val)
    {
        $this->saveColumnStatus(4, $this->content);
        $this->content = $val;
    }

    public function getAnnexList()
    {
        return json_encode($this->annexList);
    }

    public function getRawAnnexList()
    {
        return $this->annexList;
    }

    public function setAnnexList($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 512) {
            SzLogger::get()->error('[MailVo] The length of column annexList exceed the limit, length / limit: ' . $encodedLength . ' / 512');
            throw new SzException(10522, array('MailVo', '512', $encodedLength));
        } else if ($encodedLength > 460) {
            SzLogger::get()->warn('[MailVo] The length of column annexList exceed the warning level, length / limit: ' . $encodedLength . ' / 512');
        }
        $this->saveColumnStatus(5, $this->annexList);
        $this->annexList = $val;
    }

    public function getIsDel()
    {
        return $this->isDel;
    }

    public function setIsDel($val)
    {
        $this->saveColumnStatus(6, $this->isDel);
        $this->isDel = $val;
    }

    public function getIsRead()
    {
        return $this->isRead;
    }

    public function setIsRead($val)
    {
        $this->saveColumnStatus(7, $this->isRead);
        $this->isRead = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(8, $this->createTime);
        $this->createTime = $val;
    }

}